package com.hhkj.admin.course.service.base.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hhkj.admin.course.common.cont.CourseConst;
import com.hhkj.admin.course.domain.Course;
import com.hhkj.admin.course.domain.CourseBankType;
import com.hhkj.admin.course.mapper.CourseBankTypeMapper;
import com.hhkj.admin.course.model.dopo.CourseBankTypeDo;
import com.hhkj.admin.course.model.dopo.CourseBankTypePo;
import com.hhkj.admin.course.service.base.CourseBankTypeService;
import com.ruoyi.common.base.biz.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 课程题库类型Service业务层处理
 *
 * @author ruoyi
 * @since 2023-05-11
 */
@Service
public class CourseBankTypeServiceImpl
        extends BaseServiceImpl<CourseBankType, CourseBankTypeDo, CourseBankTypePo, CourseBankTypeMapper>
        implements CourseBankTypeService
{
    @Override
    public Map<Long, List<CourseBankType>> groupByCourseIdList(List<Long> courseIdList) {
        if (ObjectUtil.isEmpty(courseIdList)) {
            return new HashMap<>();
        }
        LambdaQueryWrapper<CourseBankType> queryWrapper = new LambdaQueryWrapper<CourseBankType>()
                .select(CourseBankType::getCourseId, CourseBankType::getId)
                .in(ObjectUtil.isNotEmpty(courseIdList), CourseBankType::getCourseId, courseIdList)
                .eq(CourseBankType::getDefaultFlag, CourseConst.DefaultBank.DEFAULT.getCode());
        return list(queryWrapper).stream().collect(Collectors.groupingBy(CourseBankType::getCourseId));
    }
}
